package com.ruoyi.hr.controller.hr.changemanage.empconcurrentlymanage;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.PublicService;
import com.ruoyi.hr.service.changemanage.empconcurrentlymanage.EmpConcurrentlyManageService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * @author zeo
 * @explain 员工兼任管理
 * @date 2020/4/18
 */
@Controller
@RequestMapping("/changeManage/EmpConcurrentlyManage")
public class EmpConcurrentlyManageController extends BaseController {

    @Autowired
    EmpConcurrentlyManageService empConcurrentlyManageService;

    @Autowired
    AuthorityService authorityService;

    @Autowired
    private PublicService publicService;

    private String prefix = "hr/changemanage/empconcurrentlymanage";

    //兼任登记
    @GetMapping("/registerList")
    public String concurrentlyRegisterList() {
        return prefix + "/concurrentlyRegister";
    }

    @RequestMapping("/registerList")
    @ResponseBody
    public TableDataInfo concurrentlyRegisterList(@RequestParam Map map) {
        return getDataTable(empConcurrentlyManageService.findConcurrentlyRegisterList(map));
    }

    @GetMapping("/addRegister")
    public String addPerson() {
        return prefix + "/addConcurrentlyRegister";
    }

    @RequestMapping("/addRegister")
    @ResponseBody
    public TableDataInfo addPerson(@RequestParam Map map) {
        return getDataTable(publicService.addPerson(map));
    }

    @PostMapping("/addProcedure")
    @ResponseBody
    public BaseResult procedure(String allEid, String allName, String procedure, String type) {
        return publicService.procedure(allEid, allName, procedure, type);
    }

    @PostMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId, String allName, String procedure) {
        return publicService.procedure(allId, allName, procedure);
    }

    @GetMapping("/editRegister/{id}")
    public String editRegister(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("register", empConcurrentlyManageService.findConcurrentlyRegister(id));
        mmap.put("comp", empConcurrentlyManageService.findComp());
        mmap.put("jobGrade", empConcurrentlyManageService.findJobGrade());
        return prefix + "/editConcurrentlyRegister";
    }

    @PostMapping("/editRegister")
    @ResponseBody
    public AjaxResult editRegister(@RequestParam Map map) {
        return toAjax(empConcurrentlyManageService.updateRegister(map));
    }

    @PostMapping("/removeRegister")
    @ResponseBody
    public AjaxResult removeRegister(String ids) {
        int num = empConcurrentlyManageService.removeRegister(ids);
        if (num == 0) {
            return error("删除中存在已确认信息，请取消确认后删除！");
        }
        return toAjax(num);
    }

    @PostMapping("/changComp")
    @ResponseBody
    public List<Map<String, Object>> changComp(String partCompIDTitle) {
        return empConcurrentlyManageService.findDep(partCompIDTitle);
    }

    @PostMapping("/changJob")
    @ResponseBody
    public List<Map<String, Object>> changJob(String partDepIDTitle) {
        return empConcurrentlyManageService.findJob(partDepIDTitle);
    }

    //终止登记

    @GetMapping("/endList")
    public String endList() {
        return prefix + "/concurrentlyEnd";
    }

    @RequestMapping("/endList")
    @ResponseBody
    public TableDataInfo endList(@RequestParam Map map) {
        return getDataTable(empConcurrentlyManageService.findConcurrentlyEndList(map));
    }

    @GetMapping("/addEnd")
    public String addEnd() {
        return prefix + "/addConcurrentlyEnd";
    }

    @RequestMapping("/addEnd")
    @ResponseBody
    public TableDataInfo addEnd(@RequestParam Map map) {
        return getDataTable(empConcurrentlyManageService.addConcurrentlyPerson(map));
    }

    @GetMapping("/editEnd/{id}")
    public String editEnd(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("editEnd", empConcurrentlyManageService.findConcurrentlyEnd(id));
        return prefix + "/editConcurrentlyEnd";
    }

    @PostMapping("/editEnd")
    @ResponseBody
    public AjaxResult editEnd(@RequestParam Map map) {
        return toAjax(empConcurrentlyManageService.updateEnd(map));
    }

    //兼任历史

    @GetMapping("/historyList")
    public String historyList() {
        return prefix + "/concurrentlyHistory";
    }

    @PostMapping("/historyList")
    @ResponseBody
    public TableDataInfo historyList(@RequestParam Map map) {
        return getDataTable(empConcurrentlyManageService.findConcurrentlyHistory(map));
    }

    //兼任信息查看
    @GetMapping("/EmpConcurrentlyInfoList")
    public String EmpConcurrentlyInfo() {
        return prefix + "/empConcurrentlyInfo";
    }

    @RequestMapping("/EmpConcurrentlyInfoList")
    @ResponseBody
    public TableDataInfo EmpConcurrentlyInfoList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(empConcurrentlyManageService.findEmpConcurrentlyInfo(map, authority));
    }
}
